package com.gjun.struts.action;

import java.util.Date;
import java.util.List;

import com.gjun.struts.bean.GjunMainTypeJsonBean;
import com.gjun.struts.bean.GjunNews;
import com.gjun.struts.resource.GjunMainTypeResourceIf;
import com.gjun.struts.resource.GjunNewsResourceIf;
import com.gjun.struts.util.JSONHelper;

public class SaveNewsAction {
    private String result;
    
    private String title;
    private String newkey;
    private Date opendate;
    private Date enddate;
    private String account;
    private String infoContent;
    
    private int maintype;
    
    
    
    
    private GjunMainTypeResourceIf mainTypeResource;
    private GjunNewsResourceIf newResource;
    
    
    public String loadAllMainType(){
    	//System.out.println("loadAllMainType=================================");
    	List<GjunMainTypeJsonBean> beans = mainTypeResource.loadAllMainType();
    	try {
			result = JSONHelper.mainTypesToJson(beans);
		} catch (Throwable e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		return "success";
    }
    
    
    public String saveNew(){
    	//System.out.println(title+"\t"+newkey+"\t"+opendate+"\t"+enddate+"\t"+account+"\t"+infoContent+"\t"+maintype);
    	GjunNews news = new GjunNews();
    	news.setAccount(account);
    	news.setEndnews(enddate);
    	news.setInfoContent(infoContent);
    	news.setNewkey(newkey);
    	news.setOpennews(opendate);
    	news.setRegdate(new Date());
    	news.setState(0);   // 0表示还没有审核
    	news.setTitle(title);
    	
    	try {
			newResource.saveNew(news, maintype);
			result = "saveSuccess";
		} catch (Exception e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
			result = "saveFaild";
		}
    	return "success";
    }
    
    
    
    
    
    

	public GjunMainTypeResourceIf getMainTypeResource() {
		return mainTypeResource;
	}

	public void setMainTypeResource(GjunMainTypeResourceIf mainTypeResource) {
		this.mainTypeResource = mainTypeResource;
	}

	public String getResult() {
		return result;
	}

	public void setResult(String result) {
		this.result = result;
	}
    
    

	public String getAccount() {
		return account;
	}

	public void setAccount(String account) {
		this.account = account;
	}

	public Date getEnddate() {
		return enddate;
	}

	public void setEnddate(Date enddate) {
		this.enddate = enddate;
	}

	public String getInfoContent() {
		return infoContent;
	}

	public void setInfoContent(String infoContent) {
		this.infoContent = infoContent;
	}

	public String getNewkey() {
		return newkey;
	}

	public void setNewkey(String newkey) {
		this.newkey = newkey;
	}

	public Date getOpendate() {
		return opendate;
	}

	public void setOpendate(Date opendate) {
		this.opendate = opendate;
	}

	public String getTitle() {
		return title;
	}

	public void setTitle(String title) {
		this.title = title;
	}


	public GjunNewsResourceIf getNewResource() {
		return newResource;
	}


	public void setNewResource(GjunNewsResourceIf newResource) {
		this.newResource = newResource;
	}


	public int getMaintype() {
		return maintype;
	}


	public void setMaintype(int maintype) {
		this.maintype = maintype;
	}
	
	
	
	
}
